<?php

namespace mpend\controllers;

use Yii;
use mpend\components\Controller;
use mpend\models\AuthorizationForm;
use mpend\models\AuthWechatForm;

/**
 * 接口授权
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class AuthorizeController extends Controller {

    /**
     * 停用token校验
     *
     * @inheritdoc
     */
    public $filterAccessToken = false;

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['POST'],
        ];
    }

    /**
     * 接口授权
     *
     * @return mixed
     */
    public function actionIndex() {
        $model = new AuthorizationForm();
        $model->load(Yii::$app->request->post(), '');
        return $model->authorize();
    }

    /**
     * 微信小程序接口授权
     * @return mixed
     */
    public function actionWechat() {
        $model = new AuthWechatForm();
        if (!$model->load(Yii::$app->request->post(), '')) {
            return $model->loadError('微信授权失败');
        }
        return $model->authorize();
    }

}
